package com.example.compose.jetsurvey.signinsignup

import androidx.lifecycle.ViewModel
import androidx.lifecycle.ViewModelProvider

class SignUpViewModel(private val userRepository: UserRepository) : ViewModel() {

    fun signUp(
        email: String,
        password: String,
        onSignUpComplete: () -> Unit
    ) {
        userRepository.signUp(email = email, password = password)
        onSignUpComplete()
    }

    fun signInAsGuest(
        onSignUpComplete: () -> Unit
    ) {
        userRepository.signInAsGuest()
        onSignUpComplete()
    }

}

class SignUpViewModelFactory : ViewModelProvider.Factory {
    override fun <T : ViewModel> create(modelClass: Class<T>): T {
        if (modelClass.isAssignableFrom(SignUpViewModel::class.java)) {
            return SignUpViewModel(UserRepository) as T
        }
        throw IllegalArgumentException("Unknown ViewModel class")
    }
}